package com.zghhost.codedemo.lambdaexpression;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;

public class LambdaExpressionTest {
	public static void main(String[] args) throws Exception {
		Callable<String> call = new Callable(){
			@Override
			public Object call() throws Exception {
				return "nihao";
			}
		};
		System.out.println(call.call());
		
		Callable<String> lcall = () -> "lnihao";
		System.out.println(lcall.call());

		new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("Hello from thread");
			}
		}).start();

		new Thread(){
			@Override
			public void run() {
				super.run();
			}
		}.start();

		//新方法:
		new Thread(
				() -> System.out.println("Hello from thread")
		).start();



		//Old way:
		List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
		for(Integer n: list) {
			System.out.println(n);
		}

		//New way:
		list.forEach(x -> System.out.println(x));

		//or we can use :: double colon operator in Java 8
		list.forEach(System.out::println);
	}
}
